package base;

import java.lang.ref.WeakReference;

/**
 * Moral :
 * Created by 卖火柴的小女孩 on 2018/2/12.
 */

public class BasePresenter<T> {

    protected WeakReference<T> mViewRef;

    public void attachView(T view) {
        mViewRef = new WeakReference<T>(view);
    }

    public boolean isViewAttached() {
        return mViewRef != null;
    }

    public void detachView() {
        if (mViewRef != null) {
            mViewRef.clear();
        }
    }

    public T getView() {
        return mViewRef.get();
    }

}